package com.yunbao.hujin.mymvpdemo3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yunbao.hujin.mymvpdemo3.define.FieldView;
import com.yunbao.hujin.mymvpdemo3.define.ViewFind;
import com.yunbao.hujin.mymvpdemo3.mvp.RequestPresenter3;
import com.yunbao.hujin.mymvpdemo3.mvp.RequestView3;
import com.yunbao.hujin.mymvpdemo3.mvp.base.AbstractMvpActivity;
import com.yunbao.hujin.mymvpdemo3.request.WeatherBean;

/**
 * 抽取出一个基类的Presenter和一个基类的Activity来做这个事情，
 * 让子类不用在写这些重复的代码。
 * 在基类当中不能写死吧，那就使用泛型来设计。
 */
public class MainActivity extends AbstractMvpActivity<RequestView3, RequestPresenter3> implements RequestView3{

    @FieldView(R.id.tv_text)
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewFind.bind(this);
    }

    //基类Activity的抽象方法
    @Override
    protected RequestPresenter3 createPresenter() {
        return new RequestPresenter3();
    }

    //Button点击事件
    public void request(View view) {
        getPresenter().clickRequest("101010100");//北京
    }


    /********----View层RequestView3接口----************/
    @Override
    public void requestLoading() {
        textView.setText("请求中,请稍后...");
    }

    @Override
    public void resultSuccess(WeatherBean bean) {
        //成功
        textView.setText(bean.getWeatherinfo().toString());
    }

    @Override
    public void resultFailure(String result) {
        //失败
        textView.setText(result);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getPresenter().interruptHttp();
    }

}
